<!DOCTYPE html>
<html>
  <head>
    <title>Iscore</title>
    <LINK rel="stylesheet" type="text/css" href="style/connect.css">
	<link href="css/bootstrap.css" rel="stylesheet">
  </head>
  <body>
  	<div id ="LOGO">
  		<img src="./style/logo/IScore.png" alt="IScore"/>
  	</div>
  	<div class="container">
		<div class="content">
		  <div class="row">
			<div class="login-form">
				<form action="./index.php" method="POST">
					<fieldset>
						 <div class="clearfix">
							
							<input type="text" id="user" class="input" name="user"placeholder = "Entrez votre login"/>
						 </div>
						<div class="clearfix">
						
						<input type="password" id="password" class="input" name="password" placeholder = "Entrez votre MdP"/>
						</div>
						<div id="texte">
							<a id="link" href="./email.php" >Mot de passe oubli&eacute; ?</a>
						</div>
						<!--
						<input name="remember_me" id="remember_me" type="checkbox" <?php if(isset($_COOKIE['cookielog'])) { echo('checked'); } ?>M&eacute;moriser</input>
						-->
						<input type="submit" class="btn btn-primary" id="valider" value="Connexion"/>
						
					</fieldset>
				</form>
			</div>
		</div>
    </div>
  </div> <!-- /container -->
<?php 
	require_once 'class/Include.php';
	session_start();
	if (isset($_POST['user']) && isset($_POST['password']) && ($_POST['user'] != "" || $_POST['password'] != "")){
  		$login = $_POST['user']; 
  		$password = $_POST['password'];

  		$users = User::getAll(array(
  			0=>array('field'=>'login','operator'=>'LIKE','value'=>$login)
		));
		
		$user = null;
		if(sizeof($users) == 1){
			$user = $users[0];
		}
		
     	if ($user != null && $user->checkPassword($password)){
			$_SESSION['userId'] = $user->getId();
			if($user->getRangAdmin()){
				$_SESSION['admin'] = 1;
				header('Location: admin/index.php');
			}
			else{
				header('Location: accueil.php');
			}
		} else {
			echo "<div id='error'><p id='message'>Login ou mot de passe incorrect</p></div>";
		}
	}
?>
  </body>
</html>
